package Liu_Test;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.LocalTime;

//蓝色线是继承 绿色虚线是接口
@WebServlet(name = "ShowLocalTime", value = "/ShowLocalTime")
public class ShowLocalTime extends HttpServlet {

    @Override
    public void init() {
        System.out.println("Calling Init() method...");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String str1 = "Current time: ";
        PrintWriter writer = resp.getWriter();
        System.out.println("Calling doGet() method...");
        System.out.println("System out local time...");

        resp.setContentType("text/html");
        resp.setCharacterEncoding("utf-8");

        writer.println("<html><body>");
        writer.print("<h1>" + str1 + "</h1>");
        LocalTime localTime = LocalTime.now();
        String str2 = localTime.toString();
        writer.println("<h1>" + str2 + "</h1>");
        writer.println("</body></html>");

        writer.close();

//        while(true)
//        {
//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
        System.out.println("Calling doPost() method...");
    }

    @Override
    public void destroy() {
        System.out.println("Calling destroy() method...");
    }

}
